#include <stdio.h>

int main() {
    int a[10000];
    int n,i,out, current, baoshu;
    scanf("%d", &n);
    for (i=0; i<n; ++i) {
        a[i] = 1;
    }
    current = 0;
    out = 0;
    while (out < n -1) {
        baoshu = 0;
        while (baoshu < 3) {
            if (*(a + current) == 1) {
                ++baoshu;
            }
            current = (current + 1) % n;
        }
        *(a + ((current + n - 1) % n)) = 0;
        ++out;
    }

    for (i=0; i<n; ++i) {
        if (*(a + i) == 1) {
            printf("%d", i+1);
            break;
        }
    }
    return 0;
}
